package com.bw.service.impl;

import com.bw.entity.TbCai;
import com.bw.entity.TbGood;
import com.bw.mapper.TbCaiMapper;
import com.bw.mapper.TbGoodMapper;
import com.bw.service.ITbCaiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ghq
 * @since 2020-05-31
 */
@Service
public class TbCaiServiceImpl extends ServiceImpl<TbCaiMapper, TbCai> implements ITbCaiService {
    @Autowired
    private TbCaiMapper mapper;
    @Autowired
    private TbGoodMapper goodMapper;
    @Override
    public List<TbCai> findlist() {
        return mapper.findlist();
    }

    @Override
    public void updatestatus(TbCai tbCai) {
        this.saveOrUpdate(tbCai);
        TbGood tbGood = goodMapper.selectById(tbCai.getGid());
        if(tbCai.getStatus()==1){
            tbGood.setKucun(tbGood.getKucun()+tbCai.getRnum());
        }
        if(tbCai.getStatus()==0){
            tbGood.setKucun(tbGood.getKucun()-tbCai.getRnum());
        }
        goodMapper.updateById(tbGood);
    }
}
